let province = document.querySelector('#province');
let city = document.querySelector('#city');
let area = document.querySelector('#area');
let town = document.querySelector('#town');
pAjax({
    url: '../php/province.php',
    //type:'get',
    dataType: 'json',
    data: {
        pid: 130000000000,
    },
}).then(res => {
    for (let i = 0; i < res.length; i++) {
        let option = document.createElement('option')
        province.appendChild(option)
        option.innerText = res[i].name;
        option.value = res[i].province_id
    }
})
$('#province').on('change', function () {
    let pid = province.value;
    pAjax({
        url: '../php/city.php',
        //type:'get',
        dataType: 'json',
        data: {
            pid:  $(this).prop('value'),
        },
    }).then(res => {
        for (let i = 0; i < res.length; i++) {
            let option = document.createElement('option')
            city.appendChild(option)
            option.innerText = res[i].name;
            option.value = res[i].city_id;
        }
       
    })
    city.length = 0;
})
$('#city').on('change', function () {
    let pid = city.value;
    pAjax({
        url: '../php/area.php',
        //type:'get',
        dataType: 'json',
        data: {
            cid: $(this).prop('value'),
        },
    }).then(res => {
        for (let i = 0; i < res.length; i++) {
            let option = document.createElement('option')
            area.appendChild(option)
            option.innerText = res[i].name;
            option.value = res[i].area_id
        }
    })
    area.length = 0;
})
$('#area').on('change', function () {
    let pid = area.value;
    pAjax({
        url: '../php/town.php',
        //type:'get',
        dataType: 'json',
        data: {
            aid:  $(this).prop('value'),
        },
    }).then(res => {
        for (let i = 0; i < res.length; i++) {
            let option = document.createElement('option')
            town.appendChild(option)
            option.innerText = res[i].name;
            //option.value = res[i].area_id
        }
    })
    town.length = 0;
})